﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using SMARTMobile.Common;
using SMARTMobile.ViewModels;

namespace SMARTMobile.Views
{
    public partial class CapNhatKhachHangPage
    {
        public CapNhatKhachHangPage()
        {
            InitializeComponent();
            this.DataContext = new CapNhatKhachHangViewModel();
        }

        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            if (this.DataContext != null && (this.DataContext is CapNhatKhachHangViewModel))
            {
                string msg;
                if (NavigationContext.QueryString.TryGetValue("msg", out msg))
                {
                    if (!string.IsNullOrEmpty(msg) && msg.Contains("IsGPS"))
                    {
                      (this.DataContext as CapNhatKhachHangViewModel).IsGPS = true;
                        GlobalInformation.IsDuyet = false;
                        
                        this.DeleteButton.Visibility = Visibility.Visible;
                    }
                    else if (!string.IsNullOrEmpty(msg) && msg.Contains("IsDuyet"))
                    {
                        (this.DataContext as CapNhatKhachHangViewModel).IsDuyet = true;
                        GlobalInformation.IsDuyet = false;
                        this.DeleteButton.Visibility = Visibility.Visible;
                        this.DuyetButton.Visibility = Visibility.Visible;
                    }
                }
            }
        }

        protected override void OnNavigatedFrom(NavigationEventArgs e)
        {
            base.OnNavigatedFrom(e);

        }

        private void Exit_Tapped(object sender, System.Windows.Input.GestureEventArgs e)
        {
            var viewModel = this.DataContext as CapNhatKhachHangViewModel;
            if (viewModel.IsGPS)
            {
                NavigationService.Navigate(new Uri("/Views/ChupHinhMainPage.xaml", UriKind.Relative));
            }
            else if (viewModel.IsDuyet)
            {
                NavigationService.Navigate(new Uri("/Views/DuyetTTLamTuyenPage.xaml?msg=" + "IsDuyet", UriKind.Relative));
            }
            else
            {
                NavigationService.Navigate(new Uri("/Views/MainPage.xaml", UriKind.Relative));
            }
        }

        public void NavigationToDuyetTTLamTuyen()
        {
            NavigationService.Navigate(new Uri("/Views/DuyetTTLamTuyenPage.xaml?msg=" + "IsDuyet", UriKind.Relative));
        }
    }
}